<template>
  <div class="my-container">
    <van-cell-group v-if="user" class="my-info">
      <van-cell class="base-info"      
        :border="false"
        center
      >
        <div class="name" slot="title">{{currentUser.user_name}}</div>
        <div class="phone" slot="title">
          <img src="/img/icon_tel.png" class="img_phone">{{currentUser.phonenumber}}
        </div>
        <div class="phone" slot="title">
          <img src="/img/icon_house.png" class="img_phone">{{currentUser.department}}
        </div>
        <van-button
          size="small"
          round
          class="update-btn"
          to="/user/profile/"
        >编辑资料</van-button>
      </van-cell>
    </van-cell-group>
    
    <div class="not-login" v-else>
      <div @click="$router.push('/login')">
        <img class="mobile" src="/img/iphone.png">
      </div>
      <div class="text">点击登录</div>
    </div>

    <div v-if="user">
      <van-cell-group title="">
        <van-cell icon="/img/my_look.png" class="logout-icon" title="我的浏览" is-link
          :to="{name:'mylook', params:{clsname:'我的浏览'}}" />
      </van-cell-group>
      <van-cell-group title="">
        <van-cell icon="/img/my_download.png" class="logout-icon" title="我的下载" is-link
          :to="{name:'mylook', params:{clsname:'我的下载'}}" />
      </van-cell-group>

      <van-cell class="logout-cell" title="退出登录" @click="onLogout" />
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getCurrentUser } from '@/api/user'
export default {
  name: 'LoginIndex',
  components: {},
  props: {},
  data () {
    return {
       currentUser: {} // 当前登录用户信息
    }
  },
  computed: {
    ...mapState(['user'])
  },
  watch: {},
  created () {
     this.loadCurrentUser()
  },
  mounted () {},
  methods: {
     async loadCurrentUser () {

     const { data } = await getCurrentUser();
   // console.log(data.data);
     this.currentUser = data.data
    },
    onLogout () {
  // 提示用户确认退出
  // 确认 -> 处理退出
  this.$dialog.confirm({
    title: '退出提示',
    message: '确认退出吗？'
  })
    .then(() => { // 确认执行这里
    // 清除用户登录状态
    this.$store.commit('setUser', null)
  })
    .catch(() => { // 退出执行这里
    // on cancel
  })
}
  }
}
</script>

<style scoped lang="less">
.my-container {
  .my-info {
    background: url("/img/bg_person.png") no-repeat;
    background-size: cover;
    .base-info {
      box-sizing: border-box;
      height: 200px;
      background-color: unset;
      padding-top: 38px;
      padding-bottom: 11px;
      .avatar {
        box-sizing: border-box;
        width: 66px;
        height: 66px;
        border: 1px solid #fff;
        margin-right: 11px;
      }
      .name {
        font-size: 20px;
        color: #fff;
        margin-bottom: 20px;
      }
      .update-btn {
        height: 16px;
        font-size: 10px;
        color: #666666;
      }
      .phone{
        font-size: 14px;
        color: #ffffffb8;
        margin-top: 10px;
        .img_phone{
          width: 0.5rem;
          height: 0.5rem;
          margin-right: 4px;
        }
      }
    }
    .data-info {
      .data-info-item {
        height: 65px;
        color: #fff;
        .text-wrap {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          .count {
            font-size: 18px;
          }
          .text {
            font-size: 11px;
          }
        }
      }
    }
    /deep/ .van-grid-item__content {
      background-color: unset;
    }
  }

  .not-login {
    height: 180px;
    background: url("/img/bg_person.png") no-repeat;
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .mobile {
      width: 66px;
      height: 66px;      
      background-size: cover;
    }
    .text {
      font-size: 14px;
      color: #fff;
    }
  }

  /deep/ .nav-grid {
    .nav-grid-item {
      height: 70px;
      .toutiao {
        font-size: 22px;
      }
      .toutiao-shoucang {
        color: #eb5253;
      }
      .toutiao-lishi {
        color: #ff9d1d;
      }
      .van-grid-item__text {
        font-size: 14px;
        color: #333333;
      }
    }
  }

  .logout-cell {
    text-align: center;
    color: #d86262;
  }
  .mb-4 {
    margin-bottom: 4px;
  }
  .logout-icon{
    line-height: 30px;
    font-size: 16px;
  .van-cell__left-icon{
    margin-right: 8px;
    line-height: 30px;
    }

  }

}
</style>